#include <xp/bas/time.h>
#include <xp/bas/stdio.h>
#include <xp/bas/memory.h>

int xp_main ()
{
	xp_utime_t a, b;
	xp_time_t t, t2;
	struct tm tm;
	int i;

	int mon = 11; 
	int day = 10;

	for (i = -100; i < 3000; i++) { 
		xp_memset (&a, 0, xp_sizeof(a));
		a.year = i - XP_UTIME_BASE_YEAR;
		a.mon = mon;
		a.day = day;
		a.hour = -1;
		a.min = 10;
		a.sec = 1000;
		a.msec = 0;
	
		xp_memset (&tm, 0, xp_sizeof(tm));
		tm.tm_year = i - XP_UTIME_BASE_YEAR;
		tm.tm_mon = mon;
		tm.tm_mday = day;
		tm.tm_hour = -1;
		tm.tm_min = 10;
		tm.tm_sec = 1000;
	
		xp_printf (XP_TEXT("--<%04.4d-%02d-%02d>---------------\n"), i, mon + 1, day);
		if (xp_utime_to_time (&a, &t) == -1) {
			xp_printf (XP_TEXT("cannot utime_to_time\n"));
		}
		else {
			xp_printf (XP_TEXT("%lld\n"), (long long)t);
		}
	
		t2 = (xp_time_t)mktime(&tm) * 1000;
		if (t2 == -1000) {
			xp_printf (XP_TEXT("  ** mktime error\n"));
		}
		else {
			xp_printf (
				XP_TEXT(">> %04.4d-%02d-%02d %02d:%02d:%02d\n"),
				tm.tm_year + XP_UTIME_BASE_YEAR, tm.tm_mon + 1, tm.tm_mday,
				tm.tm_hour, tm.tm_min, tm.tm_sec);
		}
		
		xp_printf (XP_TEXT("%lld\n"),  (long long)t2);
		xp_printf (XP_TEXT("diff = %lld\n"), t - t2);

		if (xp_time_to_utime (t, &b) == 0) {
			xp_printf (
				XP_TEXT(">> %04.4d-%02d-%02d %02d:%02d:%02d %04d\n"),
				b.year + XP_UTIME_BASE_YEAR, b.mon + 1, b.day,
				b.hour, b.min, b.sec, b.msec);
			
		}

		if (xp_utime_to_time (&b, &t2) == -1) {
			xp_printf (XP_TEXT("cannot utime_to_time2\n"));
		}
		else if (t != t2) {
			xp_printf (XP_TEXT("  %%poop poop poop poop poop%%   \n"));
		}

		xp_printf (XP_TEXT("\n"));
	}

	return 0;
}
